/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Materials;

import Raytracing.BRDF.LambertBRDF;
import Raytracing.Shaders.StripeProvider;
import SGGUI.GUIEvent;
import SGGUI.SGSlider;
import TweetRay.Exportable;
import TweetRay.UTFWriter;
import processing.core.PVector;
import Materials.MaterialFactory.Materials;
import TweetRay.UTFReader;

/**
 *
 * @author Matt
 */
public class BlackStripeShader extends P3C6Shader implements Exportable {

    StripeProvider sp;

    public BlackStripeShader(UTFReader reader) {
        super("Black Stripe");
        
        type = Materials.BLACKSTRIPES.ordinal();
        
        int param = reader.getBits(3);
        int rc = reader.getBits(2);
        int gc = reader.getBits(2);
        int bc = reader.getBits(2);

        setColor(new PVector(rc / 3.f, gc / 3.f, bc / 3.f));
        setParam(param/7.f);
        
        LambertBRDF stripes = new LambertBRDF(sp = new StripeProvider(color));
        sp.setScale(param/7.f);
        addBRDF(stripes);
        init();
    }

    public BlackStripeShader(String name, float scale, PVector color) {
        super(name, "Scale", color);
type = Materials.BLACKSTRIPES.ordinal();
        LambertBRDF stripes = new LambertBRDF(sp = new StripeProvider(color));
        sp.setScale(scale);
        addBRDF(stripes);


    }

    public void pack(UTFWriter output) {

        output.writeBits(Materials.BLACKSTRIPES.ordinal(), 5);
        writeColorBits(output);

    }

    public void GUIEventPerformed(GUIEvent e) {

        super.GUIEventPerformed(e);
        sp.setScale(((SGSlider) controls[0]).val);
    }
}
